package yf.mall.controller;

import java.util.List;

import com.yf.request.SearchParam;
import yf.mall.vo.AccountRecordVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yf.annotation.SysLog;
import java.util.Map;
import java.util.stream.Collectors;

import yf.mall.entity.AccountRecordEntity;
import yf.mall.service.AccountRecordService;
import com.yf.response.R;


/**
 * 账户记录Controller
 *
 * @author hxf
 * @email 505860922@qq.com
 * @date Mon Aug 26 18:14:10 CST 2019
 */
@RestController
@RequestMapping("/accountRecord")
public class AccountRecordController {
    @Autowired
    private AccountRecordService accountRecordService;

    /**
     * 列表账户记录
     */
    @RequestMapping("/list")
    @RequiresPermissions("account:record:list")
    public R list(@RequestBody SearchParam<AccountRecordVo> params) {
        PageHelper.startPage(params.getPage(),params.getLimit()).setOrderBy(params.getOrder());
        List<AccountRecordVo> accountRecordList = accountRecordService.queryListVo(params.getEntity());
//        accountRecordList = accountRecordList.stream().filter(accountRecordVo -> accountRecordVo.getRecord().getHide()==null||!accountRecordVo.getRecord().getHide()).collect(Collectors.toList());
        return R.ok(new PageInfo(accountRecordList));
    }

    /**
     * 查看账户记录
     */
    @SysLog("查看账户记录")
    @RequestMapping("/info/{id}")
    @RequiresPermissions("account:record:info")
    public R info(@PathVariable("id") Long id) {
        AccountRecordVo accountRecord = accountRecordService.getVo(id);

        return R.ok(accountRecord);
    }

    /**
     * 保存账户记录
     */
    @SysLog("保存账户记录")
    @RequestMapping("/save")
    @RequiresPermissions("account:record:save")
    public R save(AccountRecordEntity accountRecord) {
        accountRecordService.save(accountRecord);

        return R.ok(accountRecord);
    }

    /**
     * 修改账户记录
     */
    @SysLog("修改账户记录")
    @RequestMapping("/update")
    @RequiresPermissions("account:record:update")
    public R update(AccountRecordEntity accountRecord) {
        accountRecordService.update(accountRecord);

        return R.ok(accountRecord);
    }

    /**
     * 删除账户记录
     */
    @SysLog("删除账户记录")
    @RequestMapping("/delete")
    @RequiresPermissions("account:record:delete")
    public R delete(Long[]ids) {
        accountRecordService.deleteBatch(ids);

        return R.ok();
    }

    /**
     * 所有账户记录
     */
    @SysLog("所有账户记录")
    @RequestMapping("/queryAll")
    public R queryAll (@RequestParam Map<String,Object> params) {

        List<AccountRecordEntity> accountRecordList = accountRecordService.queryList(params);

        return R.ok(accountRecordList);
    }

    /**
    @ModelAttribute
    public SearchParam<AccountRecordEntity> searchParam(SearchParam<AccountRecordEntity> params, AccountRecordEntity accountRecord) {
        if (accountRecord != null) {
            params.setEntity(accountRecord);
        }

        return params;
    }
 **/
    /***********自定义开始***********/
}
